﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

public partial class Navbar : System.Web.UI.UserControl
{
    private bool _isLogin;          // 是否已登陆

    public bool IsLogin
    {
        get { return _isLogin; }
        set { _isLogin = value; }
    }
    private string _nickname;

    public string Nickname
    {
        get { return _nickname; }
        set { _nickname = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Logout"] != null && Convert.ToBoolean(Session["Logout"]) == true)
        {
            IsLogin = false;
            Session["UserType"] = null;
            Session["UserId"] = null;
            Session["pId"] = null;

            Session["Logout"] = false;
            return;
        }
        IsLogin = false;
        if (Session["UserType"] == null || Session["UserId"] == null || Session["pId"] == null)
        {
            IsLogin = false;
            return;
        }
        int userType = Convert.ToInt32(Session["UserType"]);
        int userId = Convert.ToInt32(Session["UserId"]);
        int pId = Convert.ToInt32(Session["pId"]);
        if (userType == 0)
        {
            if (HouseHolderManage.HasId(userId))
            {
                IsLogin = true;
            }
                
        }
        if (userType == 1)
        {
            if (ClientManage.HasId(userId))
                IsLogin = true;
        }
        if (userType == 2)
        {
            if (AdministratorManage.HasId(userId))
                IsLogin = true;
        }

        if (IsLogin)
        {
            Nickname = PersonalInformationManage.GetPersonalInformationById(pId).Nickname;
        }

        Page.DataBind();
    }
}